package cn.hdu.liang.core.service.user;

import cn.hdu.liang.core.bean.user.Employee;
import cn.hdu.liang.core.dao.user.EmployeeDao;
import cn.hdu.liang.core.query.user.EmployeeQuery;
import cn.itcast.common.page.Pagination;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 员工
 */
@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService {

    @Resource
    EmployeeDao employeeDao;

    public Integer addEmployee(Employee employee) {
        return employeeDao.addEmployee(employee);
    }

    @Transactional(readOnly = true)
    public Employee getEmployeeByKey(String id) {
        return employeeDao.getEmployeeByKey(id);
    }

    @Transactional(readOnly = true)
    public List<Employee> getEmployeesByKeys(List<String> idList) {
        return employeeDao.getEmployeesByKeys(idList);
    }

    public Integer deleteByKey(String id) {
        return employeeDao.deleteByKey(id);
    }

    public Integer deleteByKeys(List<String> idList) {
        return employeeDao.deleteByKeys(idList);
    }

    public Integer updateEmployeeByKey(Employee employee) {
        return employeeDao.updateEmployeeByKey(employee);
    }

    @Transactional(readOnly = true)
    public Pagination getEmployeeListWithPage(EmployeeQuery employeeQuery) {
        Pagination p = new Pagination(employeeQuery.getPageNo(), employeeQuery.getPageSize(), employeeDao.getEmployeeListCount(employeeQuery));
        p.setList(employeeDao.getEmployeeListWithPage(employeeQuery));
        return p;
    }

    @Transactional(readOnly = true)
    public List<Employee> getEmployeeList(EmployeeQuery employeeQuery) {
        return employeeDao.getEmployeeList(employeeQuery);
    }
}
